package com.cxf.windex.controller;

import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseController;
import com.cxf.windex.biz.WeiContentBiz;
import com.cxf.windex.entity.WeiContent;
import com.cxf.windex.entity.WeiType;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * @author chenxf
 * @date 3/8/2018
 * @description
 */
@Controller
@RequestMapping("")
public class HomeController extends BaseController{

  @Autowired
  private WeiContentBiz weiContentBiz;

  @RequestMapping(value = "/",method = RequestMethod.GET)
  public String home(Map<String,Object> map,@RequestParam(defaultValue = "1") int  page) {
      initSeo(map,"","","");
    Example example = new Example(WeiContent.class);
    Criteria criteria = example.createCriteria();
    example.setOrderByClause("crt_time desc ");
    PageHelper.startPage(page, 12);
    List<WeiContent> items = weiContentBiz.selectByExample(example);

    PageInfo<WeiContent> pageInfo = new PageInfo<WeiContent>(items);
    map.put("result",new TableResultResponse<WeiContent>(Integer.parseInt(String.valueOf(pageInfo.getTotal())),
        page, 12,
        items));

      return this.render("index");
  }


  @RequestMapping(value = "about",method = RequestMethod.GET)
  public String about(Map<String,Object> map){
    return "about";
  }

  @RequestMapping(value = "index",method = RequestMethod.GET)
  public String index(Map<String,Object> map){
    return "admin/index";
  }

  @RequestMapping(value = "home",method = RequestMethod.GET)
  public String bHome(Map<String,Object> map){
    return "admin/home";
  }

  @RequestMapping(value = "login",method = RequestMethod.GET)
  public String login(Map<String,Object> map){
    return "admin/login";
  }

  @RequestMapping(value = "reset_pwd",method = RequestMethod.GET)
  public String pwd(Map<String,Object> map){
    return "admin/reset_pwd";
  }



}
